package org.flyer.toolFrame;

import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Scanner;

@Component("index")
public class Index {
    @Resource()
    Config config;
    @Resource(name="route")
    Route route;
    public void menu() {
        //获取目录
        List<String> menuList = (List<String>) JSON.parse(config.getObjectByKey("menuList").toString());
        System.out.println("configJson:"+menuList);
        menuList.add("退出程序");
       while(true){
           if (menuList.size()==0) {
               System.out.println("暂无服务");
               break;
           }
           System.out.println("***************目录******************");
           for (int i = 0; i <menuList.size() ; i++) {
               System.out.println("\t"+(i+1)+"."+menuList.get(i));
           }
           System.out.println("************************************");
           System.out.println("请输入编号，选择操作:");
           Scanner scanner =new Scanner(System.in);
           //声明一个变量接受用户输入的值
           Integer menuIndex;
           while (true){
               menuIndex = scanner.nextInt();
               if (--menuIndex<menuList.size()){
                   System.out.println("您选择了:"+menuList.get(menuIndex));
                   break;
               }else {
                   System.out.println("您的输入有误!请输入正确编号!");
               }
           }
           if (menuIndex!=null){//调用方法路由
                route.navigation(menuList.get(menuIndex));
           }
       }
    }
}
